<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let offset = 8
    function getUTCDateTime(val, offset = 8) {
        // 取本地时间
        const localtime = val ? new Date(val) : new Date()
        // 取本地毫秒数
        const localmesc = localtime.getTime()
        // 取本地时区与格林尼治所在时区的偏差毫秒数
        const localOffset = localtime.getTimezoneOffset() * 60000
        // 反推得到格林尼治时间
        const utc = localOffset + localmesc
        // 得到指定时区时间
        return new Date(utc + (3600000 * offset))
    }

    function getDateTime(val) {
        const currentDateTime = new Date(val)
        return {
            year: currentDateTime.getFullYear(),
            month: currentDateTime.getMonth() + 1,
            day: currentDateTime.getDate(),
            hours: currentDateTime.getHours(),
            minutes: currentDateTime.getMinutes(),
            seconds: currentDateTime.getSeconds(),
            weekDay: currentDateTime.getDay() || 7,
            milliseconds: currentDateTime.getMilliseconds()
        }
    }

    function showDateTime(val, offset = 8) {
        const dateTime = new Date(val)
        const times = dateTime.getTime()
        const currentTimes = times + offset * 3600000
        const currentDateTime = new Date(currentTimes)
        return {
            year: currentDateTime.getUTCFullYear(),
            month: currentDateTime.getUTCMonth() + 1,
            day: currentDateTime.getUTCDate(),
            hours: currentDateTime.getUTCHours(),
            minutes: currentDateTime.getUTCMinutes(),
            seconds: currentDateTime.getUTCSeconds(),
            weekDay: currentDateTime.getUTCDay() || 7,
            milliseconds: currentDateTime.getMilliseconds()
        }
    }

    const val = Date.now()
    console.log(getDateTime(val))
    console.log(showDateTime(val, 6))
</script>
</body>
</html>